var app = getApp();
var api = require('../../utils/util.js').default;
Page({

  data: {
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '订单查询', //导航栏中间的标题
    },
    deliverList: [],
  },

  getUserOrder: function () {
    this.setData({deliverList:[]})
    var data = {
      openid: app.globalData.openid,
    }
    console.log('获取用户历史订单：')
    api.getUserOrder(data).then(res => {
      console.log(res.data.data)
      wx.setStorageSync('user_order', res.data.data);
      this.classifyOrder();
    })
  },

  // 订单分类
  classifyOrder:function(){
    var arr = wx.getStorageSync('user_order');
    for (let i = 0; i < arr.length; i++) {
      var singleData = arr[i];
      switch (singleData.sever_type) { //服务类型
        case "1":
          singleData.sever_type = "快递代拿";
          break;
        case "2":
          singleData.sever_type = "外卖代拿";
          break;
        case "3":
          singleData.sever_type = "食堂代拿";
          break;
        case "4":
          singleData.sever_type = "超市代买";
          break;
        default:
          singleData.sever_type = "未知类型";
      }

      switch (singleData.status) { //接单情况
        case "000":
          singleData.status_show = "匹配中";
          break;
        case "001":
          singleData.status_show = "配送中";
          break;
        case "002":
          singleData.status_show = "已送达";
          break;
        case "003":
          singleData.status_show = "待接受";
          break;
        case "004":
          singleData.status_show = "可退款";
          break;
        case "005":
          singleData.status_show = "退款中";
          break;
        case "006":
          singleData.status_show = "退款成功";
          break;
        default:
          singleData.status_show = "未知状态";
      }
      if (singleData.torider.length < 20) { //判断是否有骑手
        singleData.nickName = "【暂无骑手接单】";
      }
      let singleObject = {};
      singleObject = {
        tocustomer: singleData.tocustomer, //客户名
        sever_type: singleData.sever_type, //服务类型选择
        meet_place: singleData.meet_place, //交接地点
        unit_price: singleData.unit_price, //单价
        cus_details: singleData.cus_details, //客户的备注信息
        upload_time: singleData.upload_time, //订单提交时间
        torider: singleData.torider, //选择骑手
        status: singleData.status,
        status_show: singleData.status_show,
        img_src:singleData.head,
        rider_name:singleData.nickName,
      }
      console.log(singleObject);
      this.setData({
        deliverList: this.data.deliverList.concat(singleObject)
      });
    }
  },


  onLoad: function (options) {
    this.getUserOrder();
  },

})